import jieba
from wordcloud import WordCloud
# 读取弹幕文件
def read_file(filename):
    with open(filename, mode='r', encoding='utf-8') as f:
        dan_mu = f.read()
        return dan_mu
# 结巴分词
def jieba_cut(str):
    cut_list = jieba.lcut(str)
    return  cut_list
# 生成云词对象
def gen_word_cloud(cut_list):
    word_str = ' '.join(cut_list)
    # 生成词云对象
    wc = WordCloud(font_path='msyh.ttc').generate(word_str)
    # 保存到图片
    wc.to_file('cloud.png')
if __name__ == '__main__':
    av = 'av85102316'
    str = read_file(f'{av}.txt')
    cut_list = jieba_cut(str)
    gen_word_cloud(cut_list)
